package ch.dreamweb.readpractice.shared;

import java.io.Serializable;

import com.allen_sauer.gwt.voices.client.Sound;
import com.allen_sauer.gwt.voices.client.SoundController;

public class SoundHolder implements Serializable {

	/** Comment for <code>serialVersionUID</code>. */
	private static final long serialVersionUID = 8404020609476305195L;

	public Boolean commentsLoaded = false;
	public Boolean numbersLoaded = false;
	public Boolean wordsLoaded = false;

	public SoundController soundController = new SoundController();
	public Sound[] soundnumbers_t1 = { null, null, null, null, null, null,
			null, null, null };
	public Sound[] soundnumbers_t2 = { null, null, null, null, null, null,
			null, null, null, null, null, null, null, null, null, null, null,
			null, null, null, null, null, null, null, null, null, null, null,
			null, null, null, null, null, null, null, null, null, null, null,
			null, null, null, null, null, null, null, null, null, null, null,
			null };
	public Sound soundRight = null;
	public Sound soundWrong = null;
	public Sound soundLevel = null;
	public Sound soundEnd = null;
	public Sound soundButton = null;

	// Private constructor prevents instantiation from other classes
	private SoundHolder() {

	}

	/**
	 * SingletonHolder is loaded on the first execution of
	 * Singleton.getInstance() or the first access to SingletonHolder.INSTANCE,
	 * not before.
	 */
	private static class Info {
		public static final SoundHolder INSTANCE = new SoundHolder();
	}

	public void loadComments(String soundfileformat) {
		if (soundfileformat.equals("ogg")) {
			soundRight = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_OGG_VORBIS, "sounds/feedback/right."
							+ soundfileformat);
			soundWrong = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_OGG_VORBIS, "sounds/feedback/wrong."
							+ soundfileformat);
			soundLevel = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_OGG_VORBIS, "sounds/feedback/level."
							+ soundfileformat);
			soundEnd = soundController
					.createSound(Sound.MIME_TYPE_AUDIO_OGG_VORBIS,
							"sounds/feedback/end.mp3");
			soundButton = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_OGG_VORBIS, "sounds/feedback/button."
							+ soundfileformat);

		} else {

			soundRight = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/feedback/right."
							+ soundfileformat);
			soundWrong = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/feedback/wrong."
							+ soundfileformat);
			soundLevel = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/feedback/level."
							+ soundfileformat);
			soundEnd = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/feedback/end.mp3");
			soundButton = soundController.createSound(
					Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/feedback/button."
							+ soundfileformat);
		}
		commentsLoaded = true;
	}

	public void loadNumbers(String soundfileformat) {

		for (int i = 0; i < 9; i++) {
			if (soundfileformat.equals("ogg")) {
				soundnumbers_t1[i] = soundController.createSound(
						Sound.MIME_TYPE_AUDIO_OGG_VORBIS, "sounds/numbers/n"
								+ (i + 1) + "." + soundfileformat);
			} else {
				soundnumbers_t1[i] = soundController.createSound(
						Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/numbers/n"
								+ (i + 1) + "." + soundfileformat);
			}
		}
		;
		numbersLoaded = true;
	}

	public void loadWords(String soundfileformat) {

		for (int i = 0; i < 50; i++) {
			if (soundfileformat.equals("ogg")) {
				soundnumbers_t2[i] = soundController.createSound(
						Sound.MIME_TYPE_AUDIO_OGG_VORBIS, "sounds/words/"
								+ (i + 1) + "." + soundfileformat);
			} else {
				soundnumbers_t2[i] = soundController.createSound(
						Sound.MIME_TYPE_AUDIO_MPEG_MP3, "sounds/words/"
								+ (i + 1) + "." + soundfileformat);
			}
		}
		wordsLoaded = true;
	}

	public static SoundHolder getInstance() {
		return Info.INSTANCE;
	}

}
